using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Gadgets
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtUsername.Text.Trim() == string.Empty)
                {
                    ABSCommonLibrary.ShowMessage("Ten dang nhap khong duoc phep trong");
                    txtUsername.Focus();
                    return;
                }
                if (txtPassword.Text.Trim() == string.Empty)
                {
                    ABSCommonLibrary.ShowMessage("Mat khau dang nhap khong duoc phep trong");
                    txtPassword.Focus();
                    return;
                }
                object[] p_param = new object[2]{
                        txtUsername.Text.Trim(), txtPassword.Text.Trim()};
                string branch_id = ABSCommonLibrary.DoExecute(
                    CommonLibrary.CommonLibrary.BOSC020002, ref p_param).ToString();
                if (branch_id == string.Empty || branch_id == "0")
                {
                    ABSCommonLibrary.ShowMessage("Ten hoac mat khau dang nhap khong hop le");
                    txtUsername.Focus();
                    return;
                }
                DeclareLibrary.BRANCH_ID = branch_id;
                DeclareLibrary.USER_NAME = txtUsername.Text.Trim();
                DeclareLibrary.PASSWORD = txtPassword.Text.Trim();
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                ABSCommonLibrary.ShowErrorMessage(ex.ToString());
            }
            
            
        }

        private void Login_Load(object sender, EventArgs e)
        {
            txtUsername.Focus();
        }
    }
}